<?php
require("./gigJunkieXmlParser.php");

$genre = 'rock-pop';
$startDate = '2010-03-13';
$pageSize = 10;
$latitude = 51.51;
$longitude = -0.11;

$xmlParser = new gigJunkieXmlParser('london o2');

if ($xmlParser->setGenre($genre) === false) {
    print("Invalid genre: {$genre}");
}

if ($xmlParser->setStartDate($startDate) === false) {
    print("Invalid start date: {$startDate}");
}

if ($xmlParser->setPageSize($pageSize) === false) {
    print("Invalid page size: {$pageSize}");
}

if ($xmlParser->setLatitude($latitude) === false) {
    print("Invalid latitude: {$latitude}");
}

if ($xmlParser->setLongitude($longitude) === false) {
    print("Invalid longitude: {$longitude}");
}

do {
    /**
     * Increment the page number
     */
    if (isset($events)) {
        $xmlParser->nextPage();
    }
    
    /**
     * Try to fetch some events
     */
    if (($events = $xmlParser->fetchEvents()) === false) {
        /**
         * There was a problem either fetching or parsing the XML
         */
        print("Error! " . $xmlParser->fetchErrorMessage());
        exit;
    }
    
    /**
     * Successfully fetched and parsed the events XML. Display the results.
     */
    print("URL: " . $xmlParser->constructRequestUrl());
    print("\n\n<br /><br />Total result count = " . $xmlParser->fetchResultCount());
    print("\n\n<br /><br />" . $xmlParser->morePagesToFetch() . " more pages to fetch.");
    
    foreach ($events as $key => $event) {
        print("\n\n<br /><br /><strong>{$key})</strong> ");
        print_r($event);
    }
    
    
} while ($xmlParser->morePagesToFetch() > 0);

print("Done. No more pages to fetch.");